function dateStringFromTimestamp(timestamp){
  if (timestamp < 9999999999) {
    timestamp = timestamp * 1000;
  }
  var currentTimestamp = Date.parse(new Date());
  var interval = Math.abs(currentTimestamp - timestamp);
  if (interval <= 60 * 1000) {
    return "刚刚";
  } else if (interval <= 60 * 60 * 1000) {
    return Math.floor(interval / 1000 / 60) + "分钟前";
  } else if (interval <= 24 * 60 * 60 * 1000) {
    return Math.floor(interval / 1000 / 60 / 60) + "小时前";
  } else if (interval <= 30 * 24 * 60 * 60 * 1000) {
    return Math.floor(interval / 1000 / 60 / 60 / 24) + "天前";
  } else if (interval <= 12 * 30 * 24 * 60 * 60 * 1000) {
    return Math.floor(interval / 1000 / 60 / 60 / 24 / 30) + "月前";
  } else {
    return Math.floor(interval / 1000 / 60 / 60 / 24 / 30 / 12) + "年前";
  }
}

function getDatetime() {
    var d = new Date();
    var year = d.getFullYear();
    var month = change(d.getMonth() + 1);
    var day = change(d.getDate());
    var hour = change(d.getHours());
    var minute = change(d.getMinutes());
    var second = change(d.getSeconds());
    
    function change(t) {
        if (t < 10) {
            return "0" + t;
        } else {
            return t;
        }
    }

    var time = year + '-' + month + '-' + day + ' ' 
            + hour + ':' + minute + ':' + second;

    return time;
}

function getQueryString(url,name) {
	if (url.indexOf("?") != -1) {
		var str = url.split("?")[1];
		var strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			let key = strs[i].split("=")[0]
			let value = unescape(strs[i].split("=")[1])
			if (key == name) {
				return value
			}
		}
	}
	return null;
}

export default {
  dateStringFromTimestamp,
  getDatetime,
  getQueryString
}